module.exports = {
  requestHandle(response){
    return new Promise((resolve, reject)=>{
      if(response?.error==true){
        wx.showModal({
          title:'错误',
          content:response.errmsg,
          showCancel:false
        })
        reject({})
      }else{
        resolve(response.res);
      }
    })
  },
  request:async function(func,action,data){
    wx.showToast({
      title: 'success',
    })
      wx.showLoading({
        title: '载入中',
      })
      try{
        const response=await wx.cloud.callFunction({
          name:func,
          data:{
            action,
            data
          }
        })
        const trueResp=await this.requestHandle(response.result);
        // console.log('request','trueResp',trueResp)
        return trueResp;
      }finally{
        wx.hideLoading({
          success: (res) => {},
        })
      }
  }
};